package longrise.phone.com.bjjt_jyb.Adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.LEAP.Base.Objects.EntityBean;

import java.util.List;

import longrise.phone.com.bjjt_jyb.R;


/**
 * 事故列表的适配器
 */
public class AccidentAdapter extends BaseQuickAdapter {

    private Context mContext;

    private int type;////0未完成；1已完成

    private View.OnClickListener listener;

    public AccidentAdapter(Context context, int type, List<EntityBean> lists) {
        super(R.layout.adapter_accident_item, lists);
        this.mContext = context;
        this.type = type;
    }

    public void setOnClickListner(View.OnClickListener listner) {
        this.listener = listner;
    }


    @Override
    protected void convert(BaseViewHolder baseViewHolder, Object o) {

        //设置数据
        EntityBean bean = (EntityBean) o;
        //类型图片
        String state = bean.getString("state");
        baseViewHolder.setBackgroundRes(R.id.viewstub_iv_type, getDrawable(state));
        if (type == 0) {
            if (TextUtils.equals(state, "5") || TextUtils.equals(state, "6")
                    || TextUtils.equals(state, "15")) {
                baseViewHolder.setVisible(R.id.accident_layout_deal, false);
            } else {
                baseViewHolder.setVisible(R.id.accident_layout_deal, true);
                baseViewHolder.setTag(R.id.accident_tv_deal, bean);
                baseViewHolder.setOnClickListener(R.id.accident_tv_deal, listener);
            }
        } else {
            baseViewHolder.setVisible(R.id.accident_layout_deal, false);
        }
        //事故方
        String isSingle = bean.getString("casetype");
        //我的车辆
        String mycarno = bean.getString("casecarno");
        if (TextUtils.isEmpty(mycarno)) {
            mycarno = "";
        }
        if (TextUtils.equals("0", isSingle)) {
            baseViewHolder.setVisible(R.id.accident_tv_name, false);
            baseViewHolder.setText(R.id.accident_tv_carnum, "单车车辆：" + mycarno);
        } else {
            baseViewHolder.setVisible(R.id.accident_tv_name, true);
            String carnum = bean.getString("ocasecarno");
            if (TextUtils.isEmpty(carnum)) {
                carnum = "";
            }
            baseViewHolder.setText(R.id.accident_tv_name, "甲方车辆：" + carnum);
            baseViewHolder.setText(R.id.accident_tv_carnum, "乙方车辆：" + mycarno);
        }
        //提交时间
        String ctime = bean.getString("casehaptime");
        if (TextUtils.isEmpty(ctime)) {
            ctime = "";
        } else {
            int index = ctime.indexOf(".");
            if (index > -1) {
                ctime = ctime.substring(0, index);
            }
        }
        baseViewHolder.setText(R.id.accident_tv_time, "提交时间：" + ctime);
    }

    //根据事故状态显示图片
    private int getDrawable(String state) {
        if (TextUtils.equals(state, "1")) {// 待定责
            return R.mipmap.txt01;
        } else if (TextUtils.equals(state, "2")) {//待保险报案
            return R.mipmap.txt02;
        } else if (TextUtils.equals(state, "3")) {//待理赔
            return R.mipmap.txt03;
        } else if (TextUtils.equals(state, "4")) {//待评价
            return R.mipmap.txt04;
        } else if (TextUtils.equals(state, "5")) {// 完成
            return R.mipmap.txt05;
        } else if (TextUtils.equals(state, "6")) {//撤销案件
            return R.mipmap.txt06;
        } else if (TextUtils.equals(state, "7")) {//定责图片待审
            return R.mipmap.txt07;
        } else if (TextUtils.equals(state, "8")) {//现场处理
            return R.mipmap.txt16;
        } else if (TextUtils.equals(state, "9")) {//案件信息未上传
            return R.mipmap.txt09;
        } else if (TextUtils.equals(state, "10")) {//未生成协议书
            return R.mipmap.txt10;
        } else if (TextUtils.equals(state, "11")) {//定损待审
            return R.mipmap.txt11;
        } else if (TextUtils.equals(state, "12")) {//未上传银行卡信息
            return R.mipmap.txt12;
        } else if (TextUtils.equals(state, "13")) {//定损照片未上传
            return R.mipmap.txt13;
        } else if (TextUtils.equals(state, "14")) {//定责图片未上传
            return R.mipmap.txt14;
        } else if (TextUtils.equals(state, "15")) {//放弃理赔
            return R.mipmap.txt15;
        }
        return R.mipmap.unknow;
    }
}
